﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using dhDataAcess.orderLinqDAL;
using dhSystemBLL.orderData;
using dhDataAcess.baseBLL;
using baseSet;

namespace dhsystem.basicForm
{
    public partial class FrmproductUnitAdd : Form
    {
        productUnitBLL productunit = new productUnitBLL();
        productUnitModel productuintRow = new productUnitModel();
        productListBLL productList = new productListBLL();
        BindingSource BindingSourceproductunitAdd;
        string state;
        string pname;
        public FrmproductUnitAdd(BindingSource _bindingSourceproductunit, string _state, string _pname)
        {
            InitializeComponent();
            state = _state;
            pname = _pname;
            BindingSourceproductunitAdd = _bindingSourceproductunit;
        }
        //打开窗口时绑定数据
        private void FrmproductUnitAdd_Load(object sender, EventArgs e)
        {
            
           
            if (state == "新增")
            {
                textPunit.DataBindings.Add("text", BindingSourceproductunitAdd, "punit");
                textpname.DataBindings.Add("text", BindingSourceproductunitAdd, "pname");
                textWeightCP.DataBindings.Add("text", BindingSourceproductunitAdd, "weightCP");
                textWeightPD.DataBindings.Add("text", BindingSourceproductunitAdd, "weightPD");
                textTaxPrice.DataBindings.Add("text", BindingSourceproductunitAdd, "taxPrice");
                textPrice.DataBindings.Add("text", BindingSourceproductunitAdd, "price");
                textCurreyType.DataBindings.Add("text", BindingSourceproductunitAdd, "curreyType");
                textmark.DataBindings.Add("text", BindingSourceproductunitAdd, "mark");
                textunitNo.DataBindings.Add("text", BindingSourceproductunitAdd, "unitNo");

                BindingSourceproductunitAdd.AddNew();
                textunitNo.Text = "U" + GlobalInfo.Date + "-" + basicSql.getOrderSerail("单位编号");
                textpname.Text = pname;
                
            }
            if (state == "编辑")
            {
                textPunit.DataBindings.Add("text", BindingSourceproductunitAdd, "punit");
                textpname.DataBindings.Add("text", BindingSourceproductunitAdd, "pname");
                textWeightCP.DataBindings.Add("text", BindingSourceproductunitAdd, "weightCP");
                textWeightPD.DataBindings.Add("text", BindingSourceproductunitAdd, "weightPD");
                textTaxPrice.DataBindings.Add("text", BindingSourceproductunitAdd, "taxPrice");
                textPrice.DataBindings.Add("text", BindingSourceproductunitAdd, "price");
                textCurreyType.DataBindings.Add("text", BindingSourceproductunitAdd, "curreyType");
                textmark.DataBindings.Add("text", BindingSourceproductunitAdd, "mark");
                textunitNo.DataBindings.Add("text", BindingSourceproductunitAdd, "unitNo");


            }
   

            textPunit.Focus();
                
        }
        //保存按钮，插入或修改数据
        private void buttonOK_Click(object sender, EventArgs e)
        {
            try
            {
                DialogResult result = MessageBox.Show("是否保存资料！", "提示信息", MessageBoxButtons.YesNo);
                if (result == DialogResult.Yes)
                {

                    BindingSourceproductunitAdd.EndEdit();//编辑到完成，写到数据源
                    BindingSourceproductunitAdd.CancelEdit(); //刷新数据作用

                }
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
        }
        //取消按钮
        private void buttonCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
